package com.brossdong.socket.netty.chaibao;

import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;

/**
 * Created by brossdong on 2018/2/22.
 */
public class ServerHandler extends ChannelHandlerAdapter{

    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {

        String request = (String) msg;
        System.out.println("Server:" + msg);

        String reponse = "我是响应数据$_";
        ctx.writeAndFlush(Unpooled.copiedBuffer(reponse.getBytes()));
    }

    @Override
    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
        ctx.close();
    }
}
